<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>class类声明</title>
  </head>
  <body>
    <div></div>
    <script>
      //get set
      class Phone {
        get name(){
          console.log('名字属性被读取')
          return 'apple'
        }
        set name(newVal){//必须有一个参数
          console.log('名字属性被赋值')
        }
      }

      //实例化对象
      let s = new Phone();
      console.log(s.name)//只要我们读取这个属性get方法就会被执行，函数里面的返回值就是属性的值

      s.name = 'xiaomi'
    </script>
  </body>
</html>
